<?php namespace App\Http\Controllers;

use App\Http\Models\Train;
use App\Http\Models\User;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;



class TrainController extends Controller {

	public function index()
	{
        $title='报名培训';

        $entries=Train::getList(Input::all());

        return view('train/list',compact('title','entries'));
	}

    public function getDetail($entry)
    {
        $title='地丰培训详情';
        $input['TBCustomerID']=Session::get(User::$session_key);
        $input['TBTrainID']=$entry->TID;
        $join=Train::getJoinList($input);

        return view('train/detail',compact('title','entry','join'));
    }

    public function doJoin()
    {
        if(!User::Check())
        {
            return Redirect::to('member/index')->withInfo('请先注册！');
        }
        $res=Train::doJoin(Input::all());
        $id=Input::get('TBTrainID','');
        if($res)
        {
            return Redirect::to('train/'.$id.'/detail')->withSuccess('操作成功');
        }else{

            return Redirect::to('train/'.$id.'/detail')->withError('操作失败');
        }
    }

    public function getMyTrain()
    {
        if(!User::Check())
        {
            return Redirect::to('member/index')->withInfo('请先注册！');
        }
        $title='我的培训';

        $input=Input::all();

        $input['my']=1;

        $entries=Train::getList($input);

        return view('train/list',compact('title','entries'));
    }

}
